home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls077.patch1 / tmp / cmw301u1 / bin / rmperms / rmperms
Encoding:
Text File  |  1995-03-24  |  1.6 KB  |  92 lines

  1. #!/bin/sh
  2. #
  3. # @(#)07  1.2  relsup/cmw301u1/bin/rmperms, scosupp, sco_3.0 3/16/95 16:00:38, SecureWare, Inc.
  4. #
  5. # rmperms - remove entries from a perms list
  6. #
  7. # usage: rmperms permsfile file ...
  8.  
  9. if [ $# -lt 2 ]; then
  10.     echo >&2 "Usage: $0 permslist filename ..."
  11.     exit 1
  12. fi
  13. Perms="$1"
  14. shift
  15. if [ ! -r "$Perms" ]; then
  16.     echo >&2 "$0: $Perms: file not found"
  17.     exit 1
  18. fi
  19.  
  20. for File in "$@"; do
  21.     # make sure we need to worry about it at all
  22.     /etc/fixperm -lg "$Perms" | grep '^'"$File"'$' >/dev/null || {
  23.         echo >&2 "$0: $File: not found in perms list"
  24.         continue;
  25.     }
  26.  
  27.     # okay, now edit the perms list
  28.     awk 'BEGIN {File="'"$File"'"}
  29.         {
  30.             if ($0 ~ /^[     ]*#/ || $1 == "uid" || $1 == "gid")
  31.             {
  32.                 print;
  33.             }
  34.             else if ((Link <= Links) && ((NF == 2) || (NF == 1)))
  35.             {
  36.                 if ($1 == File)
  37.                 {
  38.                     Links--;
  39.                 }
  40.                 else
  41.                 {
  42.                     Name[Link++] = $1
  43.                 }
  44.                 if (Link > Links)
  45.                 {
  46.                     printf ("%s\t%s\t%s\t%s\t%s\t%s\n",
  47.                          Pkg, Mode, Owner, Links, Name[1], Vol);
  48.                     for (i=2; i<Link; ++i)
  49.                         printf ("\t%s\t%s\n", Name[i],
  50.                             Vol);
  51.                 Links = 0;
  52.                 Link = 0;
  53.                 }
  54.             }
  55.             else if ((Links == 0) && ((NF == 6) || (NF == 5)))
  56.             {
  57.                 Links=$4;
  58.                 if (Links > 1)
  59.                 {
  60.                     Pkg=$1;
  61.                     Mode=$2;
  62.                     Owner=$3;
  63.                     Vol=$6;
  64.  
  65.                     Link=1;
  66.                     if ($5 != File)
  67.                     {
  68.                         Name[Link++] = $5;
  69.                     }
  70.                     else
  71.                     {
  72.                         Links--;    
  73.                     }
  74.                 }
  75.                 else
  76.                 {
  77.                     Links=0;
  78.                     Link=0;
  79.                     if ($5 != File)
  80.                         print;
  81.                 }
  82.             }
  83.         }
  84.         END { exit 0; }' "$Perms" >/tmp/rmperms$$ 
  85.     if [ $? -ne 0 ]; then
  86.         echo >&2 "$0: awk failed; perms list unchanged"
  87.         rm -f /tmp/rmperms$$ 
  88.     else
  89.         mv -f /tmp/rmperms$$ "$Perms"
  90.     fi
  91. done
  92.